package ru.timofeyco.justfeelbetter.adapters;

import java.util.ArrayList;
import ru.timofeyco.justfeelbetter.R;
import ru.timofeyco.justfeelbetter.model.DayDrillTypeState;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import android.widget.TextView;

public class DayDrillsAdapter extends ArrayAdapter<DayDrillTypeState> {
	private ArrayList<DayDrillTypeState> items;
	
	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public DayDrillsAdapter(Context context, int textViewResourceId,
			ArrayList<DayDrillTypeState> objects) {
		super(context, textViewResourceId, objects);
		this.items = objects;			
	}
	
	 @Override
	 public View getView(int position, View convertView, ViewGroup parent) {
	     View view = convertView;
	     if (view == null) {
	         LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    	 view = layoutInflater.inflate(R.layout.day_result_dialog_row, null);
	     }
	     DayDrillTypeState drillTypeState = items.get(position);
	     if (drillTypeState != null) {
	         TextView nameTextView = (TextView) view.findViewById(R.id.drill_type_dialog_textview);             
	         if (nameTextView != null) {            	 
	        	 nameTextView.setText(drillTypeState.getDrillType().getName() + ":");  
	         }             
	         
	         TextView doneTextView = (TextView) view.findViewById(R.id.done_dialog_textview);             
	         if (doneTextView != null) {            	 
	        	 doneTextView.setText(Integer.toString(drillTypeState.getCount()));  
	         }             
	         	         
	         TextView needTextView = (TextView) view.findViewById(R.id.need_dialog_textview);             
	         if (needTextView != null) {            	 
	        	 needTextView.setText(Integer.toString(drillTypeState.getDrillType().getRate()));  
	         }             
	     }
	     return view;
	 }	 
}

